import requests
import parsel  # 解析数据

# url = 'https://www.jdlingyu.com/tuji'

url = 'https://www.jdlingyu.com/104212.html'

head = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36'
}

resp = requests.get(url, headers=head)

# 获取网页源代码
html_data = resp.text

# 解析数据
selector = parsel.Selector(html_data)

# ::attr()  提取标签属性名称
ing_list = selector.css('.entry-content img::attr(src)').getall()
print(ing_list)
# for img in ing_list:
#     # 访问图片连接，并且获取图片二进制的数据
#     ind_data = requests.get(img, headers=head).content
#     img_name = img.split('/')[-1]
#     with open(f'img/{img_name}', mode='wb') as f:
#         f.write(ind_data)
